package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"group-card/common/constant"
	"group-card/model/entity"
	"group-card/rpc/card/cardclient"
	"group-card/rpc/card/internal/svc"
)

type PublishFindOneLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPublishFindOneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishFindOneLogic {
	return &PublishFindOneLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PublishFindOneLogic) PublishFindOne(in *cardclient.PublishFindOneRequest) (*cardclient.PublishFindOneResponse, error) {
	var ctx context.Context
	data, err := l.svcCtx.PublishModel.FindOne(ctx, &entity.CardPublishReq{
		Id: in.Id,
	})
	if err != nil {
		return nil, err
	}

	publish := &cardclient.PublishFindOneResponse{
		Id:                 data.Id,
		PublishTime:        data.PublishTime.Format(constant.YMDHIS),
		AdminId:            data.AdminId,
		CustomerId:         data.CustomerId,
		SkinId:             data.SkinId,
		Count:              data.Count,
		BeginNumber:        data.BeginNumber,
		EndNumber:          data.EndNumber,
		Status:             data.Status,
		Type:               data.Type,
		ServiceNumber:      data.ServiceNumber,
		ServiceOrderNumber: data.ServiceOrderNumber,
		ServiceMoney:       data.ServiceMoney,
		CreateAt:           data.CreateAt.Format(constant.YMDHIS),
		UpdateAt:           data.UpdateAt.Format(constant.YMDHIS),
		DeleteAt:           data.DeleteAt.Format(constant.YMDHIS),
	}

	return publish, nil
}
